import { UnityLog } from "./common/UnityLog";
import unity from "libunity.so";
import { deviceInfo } from "@kit.BasicServicesKit";

export function Registertest() //Register + 插件名称
{
  const register = {};
  register["StaticClassTest"] = StaticClassTest;
  register["ClassObjectTest"] = new ClassObjectTest();
  register["deviceInfo"] = deviceInfo;
  return register;

}

export class StaticClassTest{
  static stringValue = "StaticClassTestJS";
  static voidFunc(){
    UnityLog.info("CSharpCallJS voidFunc call from C# !!!")
  }

  static voidFuncWithArg(intValue,boolValue,byteValue,sbyteValue,int64Value:Number,doubleValue,charValue,stringValue){
    UnityLog.info("voidFuncWithArg call from C#");
    if(intValue == 2147483647 && boolValue && byteValue == 255 && sbyteValue == -128 && intValue == 32767 && int64Value == -9223372036854776000
    && doubleValue == 1.7976931348623157e+308 && charValue == 'R' && stringValue == "HelloWorld")
      return;
    UnityLog.error("CsharpcallJS void FUnction with Arg call fromC#.Value not equal!");
  }
  static intArray = [1,2,3];
  static boolArray = [false,true,false];
  static charArray = ["A","B","C"];
  static stringArray = ["AA",'BB','CC'];

  static intFunc(a,b) {

    return a+b;
  }
  static boolFunc(){
    return true;
  }
  static byteFunc(){
    return 255;
  }
  static sbyteFunc(){
    return -128;
  }
  static int16Func(){
    return 32767;
  }
  static int64Func(){
    return -9223372036854776000;
  }
  static charFunc(){
    return "z";
  }
  static  stringFunc(aaStr,bbStr){
    return aaStr + "HelloWorldJS" + bbStr;
  }
  static objFunc(){
    return deviceInfo;
  }
  static stringArrayFunc(tmpStringArray){
    return tmpStringArray;
  }
  static JsCallCSharpFunc(){
    unity.unitySendMessage("MainCamera","Test","JS Call CSharp Success");
    return 0;
  }

  //回调函数测试
  static callbackFunc(Callback:(a,b)=>void){
    Callback(3,"ok");
    return;
  }


}

export class ClassObjectTest{
  stringValue = "ClassObjectTestJS";
  voidFunc(){
    UnityLog.info("CSharpCallJS voidFunc call from C# !!!")
  }

  voidFuncWithArg(intValue,boolValue,byteValue,sbyteValue,int64Value:Number,doubleValue,charValue,stringValue){
    UnityLog.info("voidFuncWithArg call from C#");
    if(intValue == 2147483647 && boolValue && byteValue == 255 && sbyteValue == -128 && intValue == 32767 && int64Value == -9223372036854776000
    && doubleValue == 1.7976931348623157e+308 && charValue == 'R' && stringValue == "HelloWorld")
      return;
    UnityLog.error("CsharpcallJS void FUnction with Arg call fromC#.Value not equal!");
  }
  intArray = [1,2,3];
  boolArray = [false,true,false];
  charArray = ["A","B","C"];
  stringArray = ["AA",'BB','CC'];

   intFunc(a,b) {

    return a+b;
  }
   boolFunc(){
    return true;
  }
   byteFunc(){
    return 255;
  }
   sbyteFunc(){
    return -128;
  }
   int16Func(){
    return 32767;
  }
   int64Func(){
    return -9223372036854776000;
  }
   charFunc(){
    return "Z";
  }
    stringFunc(aaStr,bbStr){
    return aaStr + "HelloWorldJS" + bbStr;
  }
   objFunc(){
    return deviceInfo;
  }
   stringArrayFunc(tmpStringArray){
    return tmpStringArray;
  }


}